import { toBeSubmittedColumns } from './toBeSubmitted.config.js'
import search from './../search/search.js';
import { shopgoodsinfofetchList, changeShelf } from '@/api/shop/goods.js'
export default {
    name: "toBeSubmitted",
    mixins: [search],
    data() {
        return {
            toBeSubmittedColumns,
            loading: false,
            loadData: [],
            page: {
                current: 1,
                total: 0,
                size: 10
            },
            selectedRowKeys: [],  //选中的数组
            selectedRows: [],
            number: 0,
            btn: [
                {
                    title: "提交审核",
                    isShow: true
                },
                {
                    title: "删除",
                    isShow: true
                },
                {
                    title: "导出",
                    isShow: true
                },
            ],
            searchForm: {},
            businessType:'',
            key:''
        }
    },
    methods: {
        getList(searchForm, page,businessType, key) {
            if (searchForm) {
                console.log(searchForm)
                this.searchForm = searchForm
            }
            if (page) {
                this.page.current = page
            }
            if (businessType) {  //业态
                this.businessType = businessType
            }
            if (key) {
                this.key = key
            }
            shopgoodsinfofetchList(Object.assign({businessType: this.businessType,  saleState: this.key, deptId: this.$store.getters.userInfo.sysUser.deptId, tenantId: this.$store.getters.userInfo.sysUser.tenantId }, searchForm ? searchForm : {}, this.page)).then(val => {
                console.log(val)
                let data = val.data
                this.page = {
                    current: data.current,
                    total: data.total,
                    size: data.size,
                }
                this.loadData = data.records
                this.loadData.forEach(item => {
                    if (item.goodsPic) {
                        if (item.goodsPic.indexOf(',') > -1) {
                            // item.goodsPic = item.goodsPic.substring(0, item.goodsPic.lastIndexOf(','))
                            item.goodsPic = item.goodsPic.split(',')[0]
                        }

                    }
                    if (item.goodsName == '无码商品') {
                        item.categoryName = "无码商品类目"
                    }
                })
                this.$emit("trigger")
            })
        },
        onShowSizeChange(current, size) {
            console.log(current, size)
            this.page.current = current
            this.page.size = size
            this.getList()
        },
        onSelectChange(selectedRowKeys, selectedRows) {
            this.selectedRowKeys = selectedRowKeys
            this.selectedRows = selectedRows;
            this.number = this.selectedRows.length
        },
        // 清空选中项
        clearSelection() {
            this.selectedRowKeys = []
            this.number = 0
        },
        handler(index) {
            if (index == 0) {
                this.submitShenHe()
            } else if (index == 1) {
                this.delete()
            } else if (index == 2) {
                this.export()
            }
        },
        switchChange(row) {
            let obj = { ...row }
            obj = {
                id: row.id,
                goodsName: row.goodsName,
                barCode: row.barCode,
            }
            if (row.shelfState == '01') {
                obj.shelfState = '00'
                changeShelf(obj).then(val => {
                    this.getList()
                    this.$message.success('商品下架成功')

                })
            } else {
                obj.shelfState = '01'
                changeShelf(obj).then(val => {
                    this.getList()
                    this.$message.success('商品上架成功')

                })
            }
        },
        // 删除
        del(row) {
            var that = this
            this.$confirm({
                title: '确定要删除商品名称为' + row.goodsName + '吗？',
                onOk() {
                    delObj(row.id).then(val => {
                        that.getList()
                        that.$message.success('删除成功')
                    })
                },
                class: 'test',
            });
        },
        edit(row) {
            this.$router.push({ path: '/shop/goods/goods_list_add', query: { businessType: this.businessType,id: row.id } })
            this.$store.commit('SET_ACCESS_goodsEdit', row)
        }
    }

} 